/*
 * ImageBoardCtrl.h
 *
 *  Created on: Apr 13, 2009
 *      Author: wrice
 */
#ifndef IMAGEBOARDPANECTRL_H_
#define IMAGEBOARDPANECTRL_H_
#include "PANEImp.h"
namespace PANEImp {

class PANEImageBoardElement: public PANEElement, IMPLEMENTS( VisualImageBoardForPANE ) {
protected:
	friend class PANEDocument;
	PANEImageBoardElement(PANEDocument * ownerDocument);

public:
	static string TagName;

public:
	void loadImageFiles( string filenamePrefix, int sequenceBegin, int sequenceEnd, string filenameSuffix, int step );
	FrameNumber getCurrentFrameNumber() const;
	void setCurrentFrameNumber( FrameNumber desiredFrameNumber );
	unsigned long getNumberOfFrames() const;

	void setModelReconstructor( ModelReconstructor * model );
	ModelReconstructor * getModelReconstructor();

	typedef enum { DrawPoint, DrawLine, Erase, Move } InteractionMethod;
	void setInteractionMethod( InteractionMethod interactionMethod );
	InteractionMethod getInteractionMethod();

	void deselectPoint();
	bool isPointSelected() const;
	FeaturePoint * getSelectedFeaturePoint() const;
	FeaturePoint * selectFeaturePoint( Point2D point );
	bool isThereFeaturePoint( Point2D point );
	float getTolerableDistanceForPoint() const;
	float getTolerableDistanceForLine() const;

public: // from PANEElement
	virtual unsigned long getWidth();
	virtual unsigned long getHeight();

public: // from VisualSegmentForPANE
	virtual unsigned long getActualWidth();
	virtual unsigned long getActualHeight();

public: // from RenderableWithOpenCV
	virtual void render( IplImage * img );

private:
	struct Impl;
	typedef vector< IplImage * > CvImages;
	typedef CvImages::iterator CvImagesModifiableIterator;
	CvImages cvImages_;
	string imagePrefix_, imageSuffix_;
	int imageSequenceNumberBegin_, imageSequenceNumberEnd_;
	FrameNumber frameNumber_;

	ModelReconstructor * model_;
	InteractionMethod interactionMethod_;
	FeaturePoint * selectedFeaturePoint_;
	Point2DPtr temporaryLineTo_;
	float tolerableDistanceForPoint_;
	float tolerableDistanceForLine_;

	void renderCircle( IplImage * img, ModelReconstructor::PointsOnFrame points, int tickness, CvScalar color );
	void renderLine( IplImage * img, ModelReconstructor::LinesOnFrame lines, CvScalar color );
	void renderLine( IplImage * img, Line2D line, CvScalar color );
	void showTemporaryLine( FeaturePoint * lineFrom, Point2D lineTo );
	bool isThereTemporaryLineToRender();

	//	FeatureLine * getNearLineWithTolerance( Point2D point ) const;

public: virtual ~PANEImageBoardElement();
};

}

#endif /* IMAGEBOARDCTRL_H_ */
